@extends('admin.common.base-master')

@section('html-head')
    <link href="{{url('css/admin/pagenum.css')}}" rel="stylesheet" />

@endsection

@section('html-body')
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="#">商品列表</a>
            <em></em>
        </div>
        @include('admin.common.goods-header')
        <div class="filter-box clearfix">

            <div class="fr">
                <a class="addBtn" href="{{route("Admin.Home.goodsIntegralSet")}}">新增</a>

            </div>
        </div>
        <div class="table-box">
            <table class="table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>商品编号</th>
                    <th>商品名称</th>
                    <th>商品封面</th>
                    <th>兑换积分</th>
                    <th>是否包邮</th>
                    <th>已兑换数量</th>
                    <th>商品库存</th>
                    <th>商品排序</th>
                    <th>商品状态</th>



                    <th>商品轮播图</th>
                    <th>商品详情图</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @if(count($goods) > 0)
                    @foreach($goods as $good)
                        <tr id="goods_{{$good->id}}">
                            <td>{{$good->id}}</td>
                            <td>{{$good->ssn}}</td>
                            <td>{{$good->name}}</td>
                            <td class="account-td" style="width: 5%;">
                                <span class="photo" style="border-radius: 100%;display:initial">
                                    @if($good->thumb_id != 0)
                                        <a target="_blank" href="{{$good->thumb_url}}" class="openimg" data-key="{{$good->thumb_id}}"><img src="{{$good->thumb_url}}" alt="{{$good->thumb_url}}"></a>
                                    @else
                                        <img src="{{url('images/default-avatar.png')}}" alt="">
                                    @endif
                                </span>
                            </td>
                            <td>{{$good->exchange_integral}}</td>
                            <td>
                                @if($good->is_free_shipping==0)
                                    不包邮
                                    @elseif($good->is_free_shipping==1)
                                    包邮
                                    @endif
                            </td>
                            <td>{{$good->sale_count}}</td>
                            <td>{{$good->stock}}</td>
                            <td>{{$good->sort}}</td>
                            <td>@if($good->is_shop == 1)<span class="color4">上架</span> @else<span class="color3">下架</span> @endif</td>
                            <td><a href="{{route('Admin.Home.goodsBannerList')}}?id={{$good->id}}">前往设置</a></td>
                            <td><a href="{{route('Admin.Home.goodsImgList')}}?id={{$good->id}}">前往设置</a></td>
                            <td>
                                <a class="color2" href="{{route("Admin.Home.goodsIntegralSet")}}?id={{$good->id}}">编辑</a> <span>|</span>
                                <a class="color2" href="{{route('Admin.Home.goodsCommentList')}}?id={{$good->id}}" >评论</a> <span>|</span>
                                <a href="javascript:void(0);" class="del" data-id="{{$good->id}}">删除 </a>
                            </td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
            </table>
        </div>
        <div class="pagelist" style="text-align: center;">
            <?php echo $goods->render(); ?>
        </div>
    </div>
    <script>
        $(function(){

            $(document).on("click",".del",function(){
                var id = $(this).attr("data-id");

                noty({
                    text: '你确定要删除吗?',
                    buttons: [
                        {addClass: 'btn btn-primary', text: '确定', onClick: function($noty) {
                                $noty.close();
                                $.ajax({
                                    url:'{{route('Api.Admin.goods.delGoods')}}',
                                    type:'post',
                                    dataType:'json',
                                    data:{id:id},
                                    success:function(obj){
                                        if(obj.level == "success"){
                                            $("#goods_"+id).hide('slow');
                                        }else{
                                            noty({type:obj.level,text:obj.message,timeout:600});
                                        }
                                    },
                                    error:function(obj){
                                        console.log(obj);
                                    }

                                });
                            }
                        },
                        {addClass: 'btn btn-danger', text: '取消', onClick: function($noty) {
                                $noty.close();
                            }
                        }
                    ]
                });

            });
        });
    </script>
@endsection